﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.BLL.Calendar;
using Jzy.Core.Common.Web;

using Jzy.Core.Common;
using Jzy.Model.Calendar;
using Frame.Lib.Web;
using Frame.Lib.Utilities;
using Frame.Lib.Common;


namespace Jzy.Web.Calendar
{
    public partial class Management : PageList
    {
        private CalendarBO Calendar
        {
            get
            {
                return CalendarBO.Instance<CalendarBO>();
            }
        }

        private string CreatorName
        {
            get
            {
                return Request.QueryString["CreatorName"];
            }
        }
       
        private string PageSize
        {
            get
            {
                return Request.QueryString["PageSize"];
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Pager.BindDrp(drpPager);

                if (!string.IsNullOrEmpty(this.PageSize))
                {
                    drpPager.SelectedValue = this.PageSize;
                }
                if (!string.IsNullOrEmpty(this.CreatorName))
                {
                    txtCreatorName.Text = this.CreatorName;
                }
              

                //_setting.SortExpression = "InputTime";
                //_setting.SortDirection = Jzy.Core.Common.SortDirection.desc;
                BindView();

                //CustSort.SwapSortDirection(_setting);//必须要在绑定之后
            }
            InitSelectID(hidSelectIDs);
            JSUtil.SetTableHeight("list", 145);
            AddAttr();
        }

        private void AddAttr()
        {
            JSUtil.DelConfirm(btnDelete, "日程记录，将不可恢复");
            JSUtil.ClickBtn(lnkDelete, btnDelete);


        }

        private void BindView()
        {
            LVUtil.Init(lv, lvHeader);
            chkSelectAll.Checked = false;


            //GVUtil.InitGV(gvList);
            //Pager.SetPageSize(_setting, drpPager);
            PagerSetting setting = new PagerSetting();
            setting.PageIndex = this.PageIndex;
            setting.PageSize = int.Parse(drpPager.SelectedValue);

            setting.OrderBy = "InputTime desc";

            if (txtCreatorName.Text != "")
            {
                setting.Where = "CreatorName = @p0";
            }


            IEnumerable<CalendarInfo> list = this.Calendar.GetList(setting, txtCreatorName.Text);

            // setting.RecordCount = 80;
            lv.DataKeyNames = new string[] { "ID" };
            lv.DataSource = list;
            lv.DataBind();

            string prefix = GlobalVar.WebCurrPath + "Management.aspx?PageSize=" + drpPager.SelectedValue + "&CreatorName=" + Server.UrlEncode(txtCreatorName.Text) ;

            litPager.Text = HtmlPager.Render(setting, prefix, true);
            // _sorter.SetInitSort();//初始化排序字段

        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (strSelectIDs != "")
            {
                this.Calendar.Delete(StrUtil.SplitToStr(strSelectIDs));
                BindView();
            }
        }
        protected void drpPager_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindView();
        }    
   
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            BindView();
        }       
    }
}